﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

public class CandySymbol
{

    private int x;
    private int y;

    public int X
    {
        get => x; set
        {
            if (IsMovable())
            {
                x = value;
            }
        }
    }
    public int Y
    {
        get => y; set
        {
            if (IsMovable())
            {
                y = value;
            }
        }
    }

    private GameCore.PieceType pieceType;
    public GameCore.PieceType PieceType { get => pieceType; }


    private GameCore gameCore;
    public GameCore GCore
    {
        get
        {
            return gameCore;
        }
    }

    private MovableCandy moveCandy;
    public MovableCandy MoveCandy { get => moveCandy; }


    private CandyView candView;


    public GameObject mObj;

    public void Init(int _x, int _y, GameCore core, GameCore.PieceType _pieceType)
    {
        x = _x;
        y = _y;
        gameCore = core;
        pieceType = _pieceType;
        candView = gameCore.candyViews[x, y];
        if (pieceType == GameCore.PieceType.NORMAL)
        {
            moveCandy = new MovableCandy();
            moveCandy.Init(this);
        }
    }


    public bool IsMovable()
    {
        return moveCandy != null;
    }

    public class MovableCandy
    {
        private CandySymbol candy;

        public void Init(CandySymbol _candy)
        {
            candy = _candy;
        }


        public void Move(int newX,int newY)
        {
            candy.X = newX;
            candy.y = newY;
            float newXPos = candy.GCore.mapTiles[newX, newY].XPos;
            float newYPos = candy.GCore.mapTiles[newX, newY].YPos;
            candy.candView.ResPos(newXPos,newYPos);
        }

    }

}

